package ar.edu.unicen.exa.oop.bbquery.model.forum;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.annotations.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ar.edu.unicen.exa.oop.bbquery.model.forum.topic.Topic;

/**
 * Class that models a Forum
 * 
 * @author nicolas
 * 
 */
@Entity
public class DefaultForum implements Forum {

	private static Logger log = LoggerFactory.getLogger(DefaultForum.class);

	@Override
	public Integer getId() {
		return id;
	}

	private Integer id;

	private HashMap<Integer, Topic> topics;

	DefaultForum() {
	}

	private String Title;

	DefaultForum(String title) {
		log.info("Forum ( {} ) Created ", title);
		setTitle(title);
		setTopics(new HashMap<Integer, Topic>());
	}

	DefaultForum(HashMap<Integer, Topic> topics, String title) {
		log.info("Forum ( {} ) Created ", title);
		setTitle(title);
		setTopics(topics);
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		Title = title;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ar.edu.unicen.exa.oop.bbquery.model.forum.IForum#getTitle()
	 */
	public String getTitle() {
		return Title;
	}

	/**
	 * @param topics
	 *            the topics to set
	 */
	public void setTopics(Map<Integer, Topic> topics) {
		this.topics = new HashMap<Integer, Topic>(topics);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ar.edu.unicen.exa.oop.bbquery.model.forum.IForum#getTopics()
	 */
	public Map<Integer, Topic> getTopics() {
		return topics;
	}

	@Override
	public void setId(Integer id) {
		this.id = id;
	}

	public Topic getTopic(Integer postString) {
		return topics.get(postString);
	}

	public void putTopic(Topic Tpc) {
		this.topics.put(Tpc.getId(), Tpc);
	}
}
